package gui;

import javax.swing.table.*;

import java.util.ArrayList;

import model.*;
import control.SupplierCtrl;

public class SupplierTableList extends DefaultTableModel
{
	private ArrayList<Supplier> s = new ArrayList<Supplier>();
	
	public SupplierTableList()
	{
		
	}
	
	@Override
	public boolean isCellEditable(int row, int column)
	{
		return false;
	}
	
	public void setS(ArrayList<Supplier> _s)
	{
		s = _s;
		fireTableDataChanged();
	}
	
	public ArrayList<Supplier> getS()
	{
		return s;
	}
	
	@Override
    public int getColumnCount()
	{
        return 5;
	}
	
	@Override
	public int getRowCount()
	{
		if(s == null)
		{
			return 0;
		}
		else
		{
			return s.size();
		}
	}
	
	@Override
    public String getColumnName(int column)
	{
        String columnName = "";
        switch (column)
        {
            case 0:
                columnName = "Name";
                break;
            case 1:
                columnName = "Address";
                break;
            case 2:
                columnName = "Country";
                break;
            case 3:
                columnName = "PhoneNo";
                break;
            case 4:
                columnName = "Email";
                break;
        }
        return columnName;
    }
	
	@Override
	public Object getValueAt(int row, int column)
	{
		Object value = null;
		switch (column)
		{
		case 0:
			value = s.get(row).getName();
			break;
		case 1:
			value = s.get(row).getAddress();
			break;
		case 2:
			value = s.get(row).getCountry();
			break;
		case 3:
			value = s.get(row).getPhoneno();
			break;
		case 4:
			value = s.get(row).getEmail();
		}
		return value;
	}
}
